import Vue from 'vue'
import Vuex from 'vuex'
import user from './modules/user'
import todo from './modules/todo'
import wish from './modules/wish'
import achievement from './modules/achievement'
import category from './modules/category'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 全局状态
    isLoading: false,
    networkType: 'unknown'
  },
  mutations: {
    // 全局状态变更
    SET_LOADING(state, isLoading) {
      state.isLoading = isLoading
    },
    SET_NETWORK_TYPE(state, type) {
      state.networkType = type
    }
  },
  actions: {
    // 获取网络状态
    getNetworkType({ commit }) {
      uni.getNetworkType({
        success: (res) => {
          commit('SET_NETWORK_TYPE', res.networkType)
        }
      })
    }
  },
  modules: {
    user,
    todo,
    wish,
    achievement,
    category
  }
}) 